package com.wandian.weather.adapter;

import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mylib.widget.shape.RoundTextView;
import com.mylib.widget.shape.RoundViewDelegate;
import com.wandian.weather.R;
import com.wandian.weather.bean.AqiBean;
import com.wandian.weather.bean.WeatherBean;
import com.wandian.weather.tools.WeatherUtil;

/**
 * 15天天气列表数据-适配器
 */
public class WeatherFifteenDayAdapter extends BaseQuickAdapter<WeatherBean, BaseViewHolder> {

    public WeatherFifteenDayAdapter(int layoutResId) {
        super(layoutResId);
    }


    @Override
    protected void convert(BaseViewHolder helper, WeatherBean item) {

        RelativeLayout rl_15_day_view = helper.getView(R.id.rl_15_day_view);
        TextView tv_15_day_data = helper.getView(R.id.tv_15_day_data);
        TextView tv_15_day_week = helper.getView(R.id.tv_15_day_week);
        TextView tv_15_day_tq = helper.getView(R.id.tv_15_day_tq);

        TextView tv_15_day_wd = helper.getView(R.id.tv_15_day_wd);
        RoundTextView rtv_aqi = helper.getView(R.id.rtv_aqi);
        ImageView iv_15_day_weather = helper.getView(R.id.iv_15_day_weather);
        if(helper.getLayoutPosition()==0){
            rl_15_day_view.setBackgroundResource(R.color.transparent);
            tv_15_day_data.setAlpha(0.5f);
            tv_15_day_week.setAlpha(0.5f);
            tv_15_day_tq.setAlpha(0.5f);
            tv_15_day_wd.setAlpha(0.5f);
            rtv_aqi.setAlpha(0.5f);
            iv_15_day_weather.setAlpha(0.5f);
        }else {
            if(helper.getLayoutPosition()%2==1){
                rl_15_day_view.setBackgroundResource(R.color.transparent_one);
                // rl_15_day_view.setAlpha(0.4f);
            }else {
                rl_15_day_view.setBackgroundResource(R.color.transparent);
                // rl_15_day_view.setAlpha(1);
            }
        }

        iv_15_day_weather.setImageResource(WeatherUtil.getWeatherStateImage(item.getDayWeather()+"",false));
        tv_15_day_data.setText(item.getDate()+"");
        tv_15_day_week.setText(item.getWeek());
        String day_weather_text = item.getDayWeather()+"";
        tv_15_day_tq.setText(day_weather_text);
        tv_15_day_wd.setText(item.getDayTemp()+"/"+item.getNightTemp()+"°");
        setAqi(rtv_aqi,item.getAqiBean());
    }
    public void setAqi(RoundTextView rtvAqi, AqiBean aqiBean){
        if(aqiBean != null){
            Log.d("setAqi",aqiBean.getAqiName()+"");
            rtvAqi.setText(aqiBean.getAqiName());
            RoundViewDelegate delegate = rtvAqi.getDelegate();
            delegate.setBackgroundColor(aqiBean.getAqiColor());
        }else {
            rtvAqi.setText("良");
        }
    }

}
